#CROSS_COMPILE := arm-none-eabi-
CROSS_COMPILE := 

AS		= $(CROSS_COMPILE)as
CC		= $(CROSS_COMPILE)gcc
CPP		= $(CC) -E
C++		= $(CROSS_COMPILE)g++
LD		= $(CC)
#LD		= $(CROSS_COMPILE)ld
AR		= $(CROSS_COMPILE)ar
NM		= $(CROSS_COMPILE)nm
STRIP	= $(CROSS_COMPILE)strip
OBJCOPY	= $(CROSS_COMPILE)objcopy
OBJDUMP	= $(CROSS_COMPILE)objdump

RM := rm

cur_dir := $(dir $(lastword $(MAKEFILE_LIST)))

src_s := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.s))
obj_s := $(patsubst %.s, %.o, $(obj_s))

src_c := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.c))
obj_c := $(patsubst %.c, %.o, $(src_c))

src_cpp := $(patsubst $(cur_dir)%,%,$(wildcard $(cur_dir)*.cpp))
obj_cpp := $(patsubst %.cpp, %.o, $(src_cpp))

c_flag := 

cpp_flag := $(c_flag ) -std=c++11

ifeq ($(CROSS_COMPILE), "arm-none-eabi-")
l_flag := -specs=nosys.specs
endif

LDFLAGS:=-shared -fpic

TARGET := math.dll

all: $(TARGET)

$(TARGET): $(obj_s) $(obj_c) $(obj_cpp)
	$(LD) $(l_flag) $(LDFLAGS) -o $(TARGET) $(obj_s) $(obj_c) $(obj_cpp)
	
clean:
	$(RM) $(obj_s) $(obj_c) $(obj_cpp) $(TARGET)

$(obj_s): %o: %s
	$(CC) -c $(c_flag) -o "$@" "$<"
	
$(obj_c): %o: %c
	$(CC) -c $(c_flag) -o "$@" "$<"
	
$(obj_cpp): %o: %cpp
	$(C++) -c $(cpp_flag) -o "$@" "$<"